<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
		<li class="fa fa-remove"></li>
	</button>
	<h4 class="modal-title">批次二维码下载</h4>
</div>

<div class="modal-body">
	<div class="row">
		<input type="hidden" id="batchId" name="batchId" value="${batchId}"/>
		<div class="col-md-12">
			<a id="tttt"></a>
			<img id="batchImg" src='data:image/jpeg;base64,${qrcode}' style="width: 300px; hight: 300px;" class="img-responsive center-block">
		</div>

	</div>
	<div class="row">
		<div class="box-footer">
			<div class="pull-right">
				<button type="button" class="btn btn-default" data-btn-type="down_img">
					<i class="fa fa-pencil"></i> 下载
				</button>
			</div>
		</div>

	</div>
</div>

<script>

$(function() {
	$("[data-btn-type='down_img']").click(function () {
		downloadFileByForm();
		//downimg();
    });
	
});

function downloadFileByForm() {
	var batchId = $("#batchId").val();
    var url = "${basePath}/batch/downloadQrcode?bathchId="+batchId;
    var fileName = "testAjaxDownload.zip";
    var form = $("<form></form>").attr("action", url).attr("method", "post");
    form.append($("<input></input>"));
    form.appendTo('body').submit().remove();
}

/**
 * 根据图片生成画布
 */
function convertImageToCanvas(image) {
    var canvas = document.createElement("canvas");
    canvas.width = image.width;
    canvas.height = image.height;
    canvas.getContext("2d").drawImage(image, 0, 0);
    return canvas;
}
/**
 * 下载图片
 */
function downimg() {
    var sampleImage = document.getElementById("batchImg"),
    canvas = convertImageToCanvas(sampleImage);
    url = canvas.toDataURL("image/png");//PNG格式
    //以下代码为下载此图片功能
    var triggerDownload = $("#tttt").attr("href", url).attr("download", "order-1111111111.png");
    triggerDownload[0].click();
//    triggerDownload.remove();
}
</script>